package com.xiaoge.controller;

import com.xiaoge.entity.Person;
import com.xiaoge.service.PersonService;
import com.xiaoge.utils.ResData;
import com.xiaoge.utils.ResponseDataUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 接口
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Resource
    PersonService personService;

    @RequestMapping("/getAll")
    public ResData getAll(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",personService.getAll());
        return ResponseDataUtil.successData(map);
    }

    @RequestMapping("/del")
    public ResData del(String id){
        if(personService.delPerson(Integer.parseInt(id))){
            return  ResponseDataUtil.success();
        }
        return ResponseDataUtil.error();
    }

    @RequestMapping("/add")
    public ResData add(@RequestBody Person person){
        if(personService.addPerson(person)){
            return ResponseDataUtil.success();
        }
        return ResponseDataUtil.error();
    }

    //删除多个
    @RequestMapping("/dels")
    public ResData dels(@RequestBody Integer[] dels){
        if(personService.delsPerson(dels)){
            return ResponseDataUtil.successData(new HashMap<>());
        }
        return ResponseDataUtil.error();
    }

}
